package com.tsystems.school.jabber.DataBase.DAO;

import com.tsystems.school.jabber.DataBase.Entities.Conference;
import com.tsystems.school.jabber.DataBase.Entities.PersonalMessage;
import com.tsystems.school.jabber.DataBase.Entities.User;
import org.hibernate.HibernateException;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: Kirill
 * Date: 25.08.11
 * Time: 8:08
 * To change this template use File | Settings | File Templates.
 */
public class ConferenceDAO extends GenericDAO<Conference>{
	public ConferenceDAO(Class<Conference> type) {
		super(type);
	}

	public Long create(Conference conference){
		String serverName = "first";
		Long id = null;
		try{
			startTransaction();
			User mu = null;
			for(User u: conference.getMembers()){
				mu = (User)session.merge(u);
				List confs =  new ArrayList<Conference>();
				confs.add(conference);
				mu.setContacts(confs);
				mu.setPersonalMessages(new ArrayList<PersonalMessage>() );
			}
			session.save(conference);
			tx.commit();
		} catch (HibernateException he){
			handleHibernateException(he);
		}
		return id;
	}
}

